package schoolmath.web.pages;

import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.apache.tapestry5.annotations.Import;
import org.apache.tapestry5.annotations.InjectComponent;
import org.apache.tapestry5.corelib.components.Zone;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import schoolmath.web.components.content.*;
import schoolmath.web.services.UserService;

import javax.inject.Inject;

@Import(stylesheet = "context:/styles/Panel.css")
@RequiresAuthentication
public class Panel {

	private Logger logger = LoggerFactory.getLogger(Panel.class);
	@InjectComponent
	private Zone content;
	@InjectComponent
	private ManageUsersContent manageUsersContent;
	@InjectComponent
	private ManageRolesContent manageRolesContent;
	@InjectComponent
    private ManageUserGroupsContent manageUserGroupsContent;
    @InjectComponent
	private ManagePresentationsContent managePresentationsContent;
	@InjectComponent
	private ShowPresentationsContent showPresentationsContent;
	@Inject
	private UserService userService;

	public Zone getContent() {
		return this.content;
	}

	public String getUser() {
		return userService.getUser().toString();
	}

	public String getRole() {
		return userService.getUser().getRole().toString();
	}

	@RequiresRoles("Администратор")
	public Object onActionFromManageUsers() {
		return manageUsersContent;
	}

	@RequiresRoles("Администратор")
	public Object onActionFromManageRoles() {
		return manageRolesContent;
	}

	@RequiresRoles(value = {"Администратор", "Преподаватель"}, logical = Logical.OR)
	public Object onActionFromManagePresentations() {
		return managePresentationsContent;
	}

	@RequiresRoles(value = {"Администратор", "Преподаватель", "Студент"}, logical = Logical.OR)
	public Object onActionFromShowPresentations() {
		return showPresentationsContent;
	}
    @RequiresRoles(value = {"Администратор", "Преподаватель", "Студент"}, logical = Logical.OR)
    public Object onActionFromManageUserGroups() {
        return manageUserGroupsContent;
    }


    @RequiresAuthentication
	public Object onActionFromLogout() {
		return Logout.class;
	}

}
